package cn.s1995.sloth.bizs.config;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;

public class SentinelRules {

	public static void initImageFlowRule() {
		List<FlowRule> rules = new ArrayList<FlowRule>();
		FlowRule imageAddRule = new FlowRule();
		imageAddRule.setResource("imageAdd");
		imageAddRule.setCount(1);
		imageAddRule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER);
		imageAddRule.setMaxQueueingTimeMs(6 * 1000);
		rules.add(imageAddRule);
		FlowRule imageDeleteRule = new FlowRule();
		imageDeleteRule.setResource("imageDelete");
		imageDeleteRule.setCount(10);
		imageDeleteRule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER);
		imageDeleteRule.setMaxQueueingTimeMs(2 * 1000);
		rules.add(imageDeleteRule);
		FlowRule imageSearchRule = new FlowRule();
		imageSearchRule.setResource("imageSearch");
		imageSearchRule.setCount(1);
		imageSearchRule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER);
		imageSearchRule.setMaxQueueingTimeMs(2 * 1000);
		rules.add(imageSearchRule);
		FlowRule imageAdjustRule = new FlowRule();
		imageAdjustRule.setResource("imageAdjust");
		imageAdjustRule.setCount(5);
		imageAdjustRule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER);
		imageAdjustRule.setMaxQueueingTimeMs(2 * 1000);
		rules.add(imageAdjustRule);
		FlowRuleManager.loadRules(rules);
	}
}
